gtk-demo: Fix sliding puzzle demo
authorBenjamin Otte <otte@redhat.com>
Fri, 31 May 2019 03:23:42 +0000 (05:23 +0200)
committerBenjamin Otte <otte@redhat.com>
Sun, 2 Jun 2019 19:18:56 +0000 (21:18 +0200)
1. Menubuttons aren't buttons

2. For paintables without aspect ratios, use 1.0

demos/gtk-demo/sliding_puzzle.c

index cb5ffcf70941818e8cc1d255891c76e221a1977b..9486004605b7cd2a0afc7982db48b1823abcecbf 100644 (file)
@@ -282,6 +282,7 @@ start_puzzle (GdkPaintable *puzzle)
   GtkWidget *picture, *grid;
   GtkEventController *controller;
   guint x, y;
+  float aspect_ratio;
 
   /* Remove the old grid (if there is one) */
   grid = gtk_bin_get_child (GTK_BIN (frame));
@@ -292,7 +293,10 @@ start_puzzle (GdkPaintable *puzzle)
   grid = gtk_grid_new ();
   gtk_widget_set_can_focus (grid, TRUE);
   gtk_container_add (GTK_CONTAINER (frame), grid);
-  gtk_aspect_frame_set (GTK_ASPECT_FRAME (frame), 0.5, 0.5, (float) gdk_paintable_get_intrinsic_aspect_ratio (puzzle), FALSE);
+  aspect_ratio = gdk_paintable_get_intrinsic_aspect_ratio (puzzle);
+  if (aspect_ratio == 0.0)
+    aspect_ratio = 1.0;
+  gtk_aspect_frame_set (GTK_ASPECT_FRAME (frame), 0.5, 0.5, aspect_ratio, FALSE);
 
   /* Add a key event controller so people can use the arrow
    * keys to move the puzzle */
@@ -449,7 +453,7 @@ do_sliding_puzzle (GtkWidget *do_widget)
 
       tweak = gtk_menu_button_new ();
       gtk_menu_button_set_popover (GTK_MENU_BUTTON (tweak), popover);
-      gtk_button_set_icon_name (GTK_BUTTON (tweak), "emblem-system-symbolic");
+      gtk_menu_button_set_icon_name (GTK_MENU_BUTTON (tweak), "emblem-system-symbolic");
 
       restart = gtk_button_new_from_icon_name ("view-refresh-symbolic");
       g_signal_connect (restart, "clicked", G_CALLBACK (reshuffle), NULL);